<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03-v-bind动态绑定class(数组语法).html</title>
</head>

<body>
  <div id='app' v-cloak>
    <h2 class="title" :class="['active','line']">{{message}}</h2>
    <h2 class="title" :class="[active,line]">{{message}}</h2>

    <h2>v-bind:class 结合 v-on:click 实现点击改颜色</h2>
    <ul>
      <li v-for="(item,index) in books" v-on:click="color(index)" v-bind:class="index == cIndex ? 'green' : ''">{{item.name}}</li>
    </ul>
  </div>
  <script src='../js/vue.js'></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello Vue',
        active: 'active',
        line: 'gree',
        cIndex: '-1',
        books: [{
          id: 1,
          name: '海王'
        }, {
          id: 2,
          name: '海贼王'
        }, {
          id: 3,
          name: '海大王'
        }]
      },
      methods: {
        color: function(index) {
          console.log(index);
          this.cIndex = index
        }
      }
    })
  </script>
  <style>
    [v-cloak] {
      display: none;
    }
    
    .active {
      color: red;
    }
    
    .green {
      color: green;
    }
  </style>
</body>

</html>